#include "key.h"

uint8_t Key_read(void)
{
    if(HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_0) == 0)
        return  1;
    else if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_1) == 0)
        return  2;
    else if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_2) == 0)
        return  3;
    else if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == 0)
        return  4;
    else
        return 0;
}


uint8_t key_now, key_up, key_down, key_old;
void Key_proc(void)
{
    key_now = Key_read();
    key_down = key_now & (key_now ^ key_old);
    key_old = key_now;

    if(key_down)
    {
        switch (key_down)
        {
        case 1:
            show_mode ^= 1;
            /* code */
            break;
        case 2:
            if(show_mode == 1)
            {
                adc_value_ref += 0.3;
                if(adc_value_ref > 3.3)
                    adc_value_ref = 0;
            }


            /* code */
            break;
        case 3:
        if(show_mode == 0)
        {
            freq += 1000;
            if(freq > 10000)
                freq = 1000;
        }
            /* code */
            break;
        case 4:
            /* code */
            break;
        }
    }
}

